package com.wenlin.myproduction.util;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.wenlin.myproduction.MyApplication;
import com.wenlin.myproduction.bean.ResEn;
import com.wenlin.myproduction.bean.TaskEn;
import com.wenlin.myproduction.bean.TeacherEn;

import java.util.Random;

public class TestDefaultDataUtil {

    public static TaskEn getTask() {
        TaskEn taskEn = new TaskEn();
        taskEn.taskId = 0;
        taskEn.level = "Level "+UserManage.getInstance().getLevelName();
        taskEn.leftDays = 1095;
        TeacherEn teacherEn =getDefaultTeacher();
        taskEn.TeacherHeadUrl = teacherEn.HeadUrl;
        taskEn.TeacherName = teacherEn.Name;
        taskEn.state = TaskEn.TaskState.Finish;
        taskEn.reward = 0;
        taskEn.resEn = getResEn();
        return taskEn;
    }

    private static ResEn getResEn() {
        String json = GetJsonDataUtil.getJson(MyApplication.getMyApplicationContext(), "taskbook.json");
        ResEn resEn = new Gson().fromJson(json, ResEn.class);
        return resEn;
    }

    //获取默认老师
    public static TeacherEn getDefaultTeacher(){
//      return new TeacherEn("Kelly","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/ic_teacher_default.png");
        String key = "teacher_"+ UserManage.getInstance().getUid();
        String json = SharePreferenceUtil.getInstance().getString(key);
        TeacherEn mTeancherEn = null;
        if(!TextUtils.isEmpty(json)){
            mTeancherEn = new Gson().fromJson(json,TeacherEn.class);
        }
        if(mTeancherEn == null){
            mTeancherEn = getRondomTeacher();
            SharePreferenceUtil.getInstance().putString(key,mTeancherEn == null?"":mTeancherEn.tojson());
        }
        return mTeancherEn;
    }

    public static TeacherEn getRondomTeacher(){
        TeacherEn[] arr = new TeacherEn[]{
                new TeacherEn("Kelly","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/ic_teacher_default.png"),
                new TeacherEn("Amman","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_1.jpg"),
                new TeacherEn("Christian","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_2.jpg"),
                new TeacherEn("Billy","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_3.jpg"),
                new TeacherEn("Gino","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_4.jpg"),
                new TeacherEn("Colin","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_5.jpg"),
                new TeacherEn("Hank","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_6.jpg"),
                new TeacherEn("Ivan","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_7.jpg"),
                new TeacherEn("Cherry","http://zqres.oss-cn-hangzhou.aliyuncs.com/test/myenglish/avatar/teacher_8.jpg"),

        };
        try{
            int index = new Random().nextInt(1000);
            index = index%9;
            return arr[index];
        }catch (Exception e){
            e.printStackTrace();
        }
        return arr[0];
    }

    public static String getRondomName(){
        String[] names = new String[]{
                "James",
                "Amman",
                "Christian",
                "Billy",
                "Gino",
                "Colin",

                "Hank",
                "Jordan",
                "Ivan",
                "Nick",
                "Owen",
                "Paul",
                "Ray",
                "Gino",
                "James",
                "Mike",
                "Happy",
                "Keller",
                "Ellen",
                "Cherry",
                "Henli",
                "Tommy",
                "Tina",
                "May",
                "Leon",
                "James"
        };
        try{
            int index = new Random().nextInt(names.length-1);
            return names[index];
        }catch (Exception e){
            e.printStackTrace();
        }
        return names[0];
    }
}
